package com.lyl.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.lyl.domain.City;
import com.lyl.domain.Province;

import cn.itcast.jdbc.TxQueryRunner;

public class Dao {
	private QueryRunner qr = new TxQueryRunner();
	
	public List<Province> findAllProvince() {
		String sql = "SELECT * FROM province";
		try {
			List<Province> provinceList = qr.query(sql, new BeanListHandler<Province>(Province.class));
			return provinceList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	public List<City> findByProvince(int proID) {
		String sql = "SELECT * FROM city WHERE proID=?";
		try {
			List<City> cityList = qr.query(sql, new BeanListHandler<City>(City.class), proID);
			return cityList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
}
